package 二叉树;

import java.util.ArrayList;

public class Solution3 {
    //https://www.nowcoder.com/practice/0bf071c135e64ee2a027783b80bf781d
    public int[] inorderTraversal (TreeNode root) {
        if (root == null) {
            return new int[0];
        }
        ArrayList<Integer> arrayList = new ArrayList<>();
        int[] retleft = inorderTraversal(root.left);
        for (int i:retleft) {
            arrayList.add(i);
        }
        arrayList.add(root.val);
        int[] retright = inorderTraversal(root.right);
        for (int i:retright) {
            arrayList.add(i);
        }
        int[] ret = new int[arrayList.size()];
        for (int i = 0; i < arrayList.size(); i++) {
            ret[i] = arrayList.get(i);
        }
        return ret;
    }
}
